package com.tensquare.qa.service;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tensquare.qa.dao.ProblemDao;
import com.tensquare.qa.mapper.ProblemMapper;
import com.tensquare.qa.pojo.Problem;
import entity.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import util.IdWorker;

import java.util.List;

/**
 * @Description
 * @Date 2021/3/21 10:54
 */
@Service
public class ProblemService {
    @Autowired
    private ProblemDao problemDao;

    @Autowired
    private ProblemMapper problemMapper;

    @Autowired
    private IdWorker idWorker;

    public PageResult<Problem> newList(String labelid, Integer page, Integer size) {
        //设置分页
        Page<Problem> pages = new Page<>(page, size);
        //查询
        Page<Problem> problemPage = pages.setRecords(problemMapper.newlist(labelid,pages));
        //返回记录和总数
        return new PageResult(problemPage.getTotal(),problemPage.getRecords());
    }

    public PageResult<Problem> hotlist(String labelid, Integer page, Integer size) {
        //设置分页
        Page<Problem> pages = new Page<>(page, size);
        //查询
        Page<Problem> problemPage = pages.setRecords(problemMapper.hotlist(labelid,pages));
        //返回记录和总数
        return new PageResult(problemPage.getTotal(),problemPage.getRecords());
    }

    public PageResult<Problem> waitlist(String labelid, Integer page, Integer size) {
        //设置分页
        Page<Problem> pages = new Page<>(page, size);
        //查询
        Page<Problem> problemPage = pages.setRecords(problemMapper.waitlist(labelid,pages));
        //返回记录和总数
        return new PageResult(problemPage.getTotal(),problemPage.getRecords());
    }
}
